package com.wjr.view;

import com.wjr.controller.MyTankController;
import com.wjr.entity.MyTank;
import com.wjr.entity.Wall;
import com.wjr.property.GameWindowProperty;

import javax.swing.*;

public class GameWindow {

    public GameWindow (){
        launch();
    }
    public void launch(){

        JFrame jFrame = new JFrame();
        MyTank myTank = new MyTank();
        Wall wall = new Wall();
        MyTankController myTankController = new MyTankController(myTank);
        GamePanel gamePanel = new GamePanel(myTank,wall);
        //将GamePanel放入主窗口中
        jFrame.add(gamePanel);

        //添加键盘按下事件
        jFrame.addKeyListener(myTankController);

        //设置主窗口标题和大小
        jFrame.setTitle(GameWindowProperty.TITLE);
        jFrame.setSize(GameWindowProperty.WIDTH,GameWindowProperty.HEIGHT);

        //窗口是否显示
        jFrame.setVisible(true);

        //设置窗口出现位置
        jFrame.setLocationRelativeTo(null);

        //点击关闭可关闭窗口
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        //是否可以改变窗口大小
        jFrame.setResizable(false);



    }
}
